package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.gourdchild.GourdChildConfig;
import com.yanqu.road.entity.activity.gourdplant.GourdPlantConfig;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eItemId;
import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.gourdchild.GourdChildMgr;
import com.yanqu.road.server.manger.activity.gourdplant.GourdPlantMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

public class GourdChildRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        GourdChildConfig gourdChildConfig = GourdChildMgr.getConfig();
        if (gourdChildConfig != null) {
            ActivityInfo activityInfo = gourdChildConfig.getActivityInfo();
            long recycleTime = activityInfo.getEndTime() * 1000L + 600 * 1000;
            //标记体力道具
            List<String> paramList = new ArrayList<>();
            paramList.add(String.valueOf(gourdChildConfig.getEnergyRecItemId()));
            paramList.add(String.valueOf(gourdChildConfig.getScoreItemId()));
            paramList.add("1");
            paramList.add(activityInfo.getActivityName());
            ActivityItemRecycleMgr.addRecycleItemData(gourdChildConfig.getEnergyRecItemId(), activityType, 1, recycleTime, paramList);

            //标记无根水
            recycleTime = activityInfo.getEndShowTime() * 1000L + 600 * 1000;
            ActivityItemRecycleMgr.addRecycleItemData(eItemId.GOURD_CHILD_WATER_ITEM_ID.getValue(), activityType, 2, recycleTime, new ArrayList<>());

            //标记葫芦种子  ---- 【【优化】黑风寨活动不回收抽服装道具--服务端】https://www.tapd.cn/33446079/prong/tasks/view/1133446079001038937
//            paramList = new ArrayList<>();
//            paramList.add(activityInfo.getActivityName());
//            ActivityItemRecycleMgr.addRecycleItemData(eItemId.GOURD_CHILD_SEED_ITEM_ID.getValue(), activityType, 3, recycleTime,paramList);


        }

        GourdPlantConfig gourdPlantConfig = GourdPlantMgr.getConfig();
        if (gourdPlantConfig != null) {
            ActivityInfo activityInfo = gourdPlantConfig.getActivityInfo();
            long recycleTime = activityInfo.getEndTime() * 1000L + 600 * 1000;
            //标记体力道具
            List<String> paramList = new ArrayList<>();
            paramList.add(String.valueOf(eItemId.GOURD_PLANT_USE_ITEM.getValue()));
            paramList.add(String.valueOf(eItemId.GOURD_PLANT_SCORE_ITEM.getValue()));
            paramList.add("1");
            paramList.add(activityInfo.getActivityName());
            ActivityItemRecycleMgr.addRecycleItemData(eItemId.GOURD_PLANT_USE_ITEM.getValue(), activityType, 1, recycleTime, paramList);

            int exchangeItemId = gourdPlantConfig.getExchangeItemId();
            recycleTime =  activityInfo.getEndShowTime() * 1000L + 600 * 1000;
            ActivityItemRecycleMgr.addRecycleItemData(exchangeItemId, activityType, 2, recycleTime, new ArrayList<>());
        }

    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.GourdChildActivity.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int recycleType = data.getRecycleType();
        if (recycleType == 1) {
            item2Score(userId, data);
        } else if (recycleType == 2) {
            int itemId = data.getItemId();
            UserBagItem bagItem = getUserBagItem(userId, itemId);
            removeItem(bagItem);
        }
//        else if (recycleType == 3) {
//            removeActivityItemAfterEndShowTime(userId, data);
//        }
    }


/*
    public void removeActivityItemAfterEndShowTime(long userId, ActivityItemRecycleData data) {
        Property reward;
        long removeCount;
        GoodsInfo removeGoodsInfo;
        GoodsInfo toGoodsInfo;
        int removeItemId = data.getItemId();
        UserBagItem removeItem = getUserBagItem(userId, removeItemId);
        if (null == removeItem || removeItem.getNum() <= 0) {
            return;
        }
        removeCount = removeItem.getNum();
        removeGoodsInfo = GoodsMgr.getGoodsById(removeItemId);
        if (null == removeGoodsInfo) {
            log.error("remove Activity Item After End Show Time error, removeItem no found, removeGoodsId:{}, remove count:{}", removeItemId, removeCount);
            return;
        }
        toGoodsInfo = GoodsMgr.getGoodsById(Integer.valueOf(removeGoodsInfo.getExtendParam()));
        if (null == toGoodsInfo) {
            log.error("remove Activity Item After End Show Time error, toItem goods no found, removeGoodsId:{}, remove count:{}", removeItemId, removeCount);
            return;
        }
        List<String> paramList = data.getParamList();
        String tmpActivityName = paramList.get(0);
        UserInfo userInfo = UserMgr.getUserInfo(userId);
        String language = userInfo.getLanguage();
        reward = new Property(toGoodsInfo.getGoodsId(), BigInteger.valueOf(removeCount));
        if (removeItem(removeItem)) {
            String rewardStr = PropertyHelper.parsePropertyToString(reward);
            if (!StringUtils.isNullOrEmpty(rewardStr)) {//有将道具转换
                String removeName = ServerLanguageMgr.getContent(removeGoodsInfo.getGoodsName(), language);
                String activityName = ServerLanguageMgr.getContent(tmpActivityName, language);
                String toName = ServerLanguageMgr.getContent(toGoodsInfo.getGoodsName(), language);
                String mailTitle = MessageFormat.format(MultipleLanguageMgr.getContent(MailManager.ACTIVITY_GOODS_AUTO_CONSUME_TITLE,
                        language), activityName);
                String mailContent = MessageFormat.format(MultipleLanguageMgr.getContent(MailManager.ACTIVITY_GOODS_AUTO_CONSUME_CONTENT,
                        language), activityName, removeName, removeCount, toName);
                MailManager.sendMail(userId, eMailType.SYSTEM.getValue(), rewardStr, mailContent, mailTitle);
            } else {
                if (removeCount > 0) {
                    log.error("remove Activity Item After End Show Time error, removeItemId={}, removeCount={}, but no reward!", removeItemId, removeCount);
                }
            }
        }
    }
*/

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
